/**
 * Created by lvlq on 16/3/12.
 */
module.exports.index = function (req, res) {
    var timeflag = 1;

    if (is_active_end()) {
        timeflag = 2;
    }
    if (is_top()) {
        timeflag = 3
    }

    var type = req.query.t;
    if (type == 3) {
        timeflag = 3;
    }

    timeflag = 3;
    res.render("home.html", {
        timeflag: timeflag
    });
};

module.exports.doall = function (req, res, next) {
    var openid = req.query.oid || req.query.openid || "";
    if (is_active_end()) {
        res.redirect("/index/menu");
        return;
    }
    if (is_top()) {
        res.redirect("/index/menu");
        return;
    }
    next();
};

/**
 * 结束日期是4月4日
 * 排行榜日期4月8日
 * @returns {boolean}
 */
var is_active_end = function () {
    var date = new Date();
    var m = parseInt(date.getMonth()) + 1;
    var d = parseInt(date.getDate());
    if (m < 4) {
        return false;
    } else if (m == 4 && d < 5) {
        return false
    }
    return true;
};

var is_top = function () {
    var date = new Date();
    var m = parseInt(date.getMonth()) + 1;
    var d = parseInt(date.getDate());
    var h = parseInt(date.getHours());
    console.log("hour:" + h);
    if (m < 4) {
        return false;
    } else if (m == 4 && d < 7) {
        return false
    } else if (m == 4 && d == 7 && h < 19) {
        return false;
    }
    return true;
};

